/*-----------------------------------------------------------------------------
 Ajax错误处理函数
 -----------------------------------------------------------------------------*/
function ajaxError(data, type) {
    var errMessage = "运行时错误：发生未知错误，请联系管理员。";

    var status = data.status;
    var statusText = data.statusText;
    //判断返回值不是 json 格式
    if (data.responseJSON !== undefined) {
        errMessage = $.parseJSON(data.responseText).message;
    }
    handleError(parseInt(status), statusText, errMessage, type);
    parent.$("#dialog_btn_ok").focus();
}
/*-----------------------------------------------------------------------------
 Ajax共通错误处理
 -----------------------------------------------------------------------------*/
function handleError(status, statusText, errMessage, type) {
    var errShowMsg = "";
    if (status === 0) {
        errShowMsg = "运行时错误：服务器无响应，请检查网络连接。";
    } else if (status === 401) {
        errShowMsg = "运行时错误：未经授权,访问被系统拒绝。";
    } else if (status === 404) {
        errShowMsg = "运行时错误：服务器找不到请求的资源。";
    } else if (status === 500) {
        errShowMsg = errMessage;
    } else if (statusText === 'parsererror') {
        errShowMsg = "运行时错误：系统无法分解JSON格式请求。";
    } else if (statusText === 'timeout') {
        errShowMsg = " 运行时错误：请求服务超时。";
    } else if (statusText === 'abort') {
        errShowMsg = " 运行时错误：退出AJAX服务请求。";
    } else {
        errShowMsg = "运行时错误：发生未知错误，请联系管理员。";
    }
    switch (type) {
        case 1:
            ShowErrorMessagePanel(errShowMsg);
            break;
        case 2:
            ShowErrorMsgWnd(errShowMsg);
            break;
            /*default:
             code to be executed if n is different from case 1 and 2*/
    }
}
/*-----------------------------------------------------------------------------
 信息显示面板
 -----------------------------------------------------------------------------*/
var timeoutProcess;
function ShowErrorMessagePanel(errMsg) {
    if (timeoutProcess !== null)
        clearTimeout(timeoutProcess);
    if ($(".error-msg").length > 0)
        $(".error-msg").remove();
    if ($(".info-msg").length > 0)
        $(".info-msg").remove();
    if ($(".success-msg").length > 0)
        $(".success-msg").remove();
    if ($(".warning-msg").length > 0)
        $(".warning-msg").remove();
    var $errMsg = $('<div class="error-msg"><i class="fa-all fa-times-circle fa-1" style="margin-right:8px;"></i>' + errMsg + '</div>');
    $('body').append($errMsg);
    // 3秒后关闭提示框
    timeoutProcess = setTimeout(function () {
        $(".error-msg").remove();
    }, 3500);
}
function ShowSuccessMessagePanel(successMsg) {
    if (timeoutProcess !== null)
        clearTimeout(timeoutProcess);
    if ($(".error-msg").length > 0)
        $(".error-msg").remove();
    if ($(".info-msg").length > 0)
        $(".info-msg").remove();
    if ($(".success-msg").length > 0)
        $(".success-msg").remove();
    if ($(".warning-msg").length > 0)
        $(".warning-msg").remove();
    var $successMsg = $('<div class="success-msg"><i class="fa-all fa-check fa-1" style="margin-right:8px;"></i>' + successMsg + '</div>');
    $('body').append($successMsg);
    // 3秒后关闭提示框
    timeoutProcess = setTimeout(function () {
        $(".success-msg").remove();
    }, 3500);
}

function ShowErrorMsgWnd(strErrMsg) {
    var errMsg = strErrMsg.replace(/[\n\r]/gi, " ");
    var ml = getMsgWidth(errMsg) + 20;
    showModal(ml, 140, '系统信息', '', null, null, 4, errMsg);
}
function ShowSuccessMsgWnd(succMsg) {
    var succMsg = succMsg.replace(/[\n\r]/gi, " ");
    var ml = getMsgWidth(succMsg);
    showModal(ml, 140, '系统信息', '', null, null, 3, succMsg);
}
//返回字符串长度，汉字*14 半角*7
function getMsgWidth(val) {
    var w = (val.match(/[^ -~]/g)).length * 14 + (val.length - (val.match(/[^ -~]/g)).length) * 7;
    w = w + 130;
    if (w < 330)
        w = 330;
    return w;
}